<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhquan@vietnambiz.com
 */

checkLoginHeader();
checkPermission();
//categoryAction();
$question = new question();
$answer = $question->viewAnswer(intval($_GET['id']));
?>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/header.php'; ?>
<script type="text/javascript" src="/admin/themes/default/js/nicEdit.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        setTimeout("closeResultMessages()",5000);
        if(typeof(bkLib)!='undefined'){
            bkLib.onDomLoaded(function(){
                if($("#question").length>0){
                    var answerEditor = new nicEditor({
                        fullPanel : true,
                        maxHeight:220
                    }).panelInstance('question');
                    answerEditor.addEvent("blur", function() {
                        document.getElementById("question").value = answerEditor.instanceById("question").getContent();
                    });
                }
            });
        }
    });

    function closeResultMessages(){
        if ( $("#rsMessages").length > 0 ) {
            document.getElementById('rsMessages').style.display = 'none';
        }
    }
    function editAnswer(url) {
        var iMyWidth;
        var iMyHeight;
        //half the screen width minus half the new window width (plus 5 pixel borders).
        iMyWidth = ((window.screen.width-500)/2);
        //half the screen height minus half the new window height (plus title and status bars).
        iMyHeight = ((window.screen.height-450)/2);
        //Open the window.
        var win2 = window.open(url,"Edit answer","status=no,width=500,height=450,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
        win2.focus();
    }
    function actionMultil(action){
        if(action=='delete_answer'){
            if (confirm("Do you want to delete these question?")){
                document.getElementById('formView').submit();
            }else{
                document.getElementById('action').value = '';
            }
        }else{
            document.getElementById('formView').submit();
        }
    }
</script>

<div id="wrapper">
    <div id="content" style="width: 98%;">
        <div id="rightnow">
            <h3 class="reallynow">
                <span>List answers</span>
                <?php
                $arrUrl = explode('?',$_SERVER['REQUEST_URI']);
                ?>
                <span style="float: right"><a href="<?php echo $arrUrl[0];?>">Back to list questions</a></span>
                <br />
            </h3>
            <div class="youhave">
                <div id="rsMessages" style="text-align: center; color: red; font-weight: bolder">
                    <?php
                    if (isset($_SESSION['rsMessages'])) {
                        echo $_SESSION['rsMessages'];
                        $_SESSION['rsMessages'] = '';
                    }
                    ?>
                </div>
                <form method="post" action="" id="formEdit">
                    <div style="padding: 0 15px;">
                        Title:<br/>
                        <input type="hidden" name="action" value="updateQuestion"/>
                        <input type="hidden" name="updateQuestion" value="1"/>
                        <input type="text" name="title" value="<?php echo $answer['rsQuestion']['title'] ?>" style="width: 400px"/>
                        <input type="submit" value="Update" />
                        <br/>Question:<br/>
                        <textarea name="question" id="question" style="width:580px;height: 100px;"><?php echo $answer['rsQuestion']['question'] ?></textarea>
                        <br/><div style="width: 60px;float: left;">Category:</div>
                        <select name="cat_id" style="width: 150px;">
                            <option <?php echo $answer['rsQuestion']['cat_id']==1?'selected':''; ?> value="1">Kiến trúc</option>
                            <option <?php echo $answer['rsQuestion']['cat_id']==2?'selected':''; ?> value="2">Phong thủy</option>
                        </select>
                        <br/><div style="width: 60px;float: left;">Top:</div>
                        <select name="top" style="width: 150px;">
                            <option <?php echo $answer['rsQuestion']['top']==1?'selected':''; ?> value="1">Yes</option>
                            <option <?php echo $answer['rsQuestion']['top']==0?'selected':''; ?> value="0">No</option>
                        </select>
                        <br/><div style="width: 60px;float: left;">Hot:</div>
                        <select name="hot" style="width: 150px;">
                            <option <?php echo $answer['rsQuestion']['hot']==1?'selected':''; ?> value="1">Yes</option>
                            <option <?php echo $answer['rsQuestion']['hot']==0?'selected':''; ?> value="0">No</option>
                        </select>
                        <br/><div style="width: 60px;float: left;">Active:</div>
                        <select name="active" style="width: 150px;">
                            <option <?php echo $answer['rsQuestion']['active']==1?'selected':''; ?> value="1">Yes</option>
                            <option <?php echo $answer['rsQuestion']['active']==0?'selected':''; ?> value="0">No</option>
                        </select>
                        <br/><br/>
                        <?php
                            $attach = $question->getFileAttach(intval($_GET['id']));
                            if($attach['id']){
                        ?>
                        Attach file: <a href="/admin_question_download.php?i=<?php echo $attach['id'];?>"><?php echo $attach['real_filename'];?></a>
                        <br/><br/>
                        <?php
                            }
                        ?>
                        <b>Sender: <?php echo $answer['rsQuestion']['fullname'] ?></b> (<?php echo $answer['rsQuestion']['email'] ?>)
                    </div>
                    
                </form>

                <form method="post" action="" id="formView">
                    <?php if ($answer['totalRow']) {
                    ?>
                            <table width="100%">
                                <tbody>
                                    <tr>
                                        <td width="40px">&nbsp;</td>
                                        <td width="140"><b>Full name</b></td>
                                        <td><b>Answer</b></td>
                                        <td style="text-align:center;" width="60px"><b>status</b></td>
                                        <td width="120" style="text-align:center; padding:5px;"><b>Date post</b></td>
                                        <td width="40px" style="text-align:center;"><b>Delete</b></td>
                                    </tr>
                            <?php
                            $i = 0;
                            while ($rs = $db->fetch_array($answer['rsAnswer'])) {
                                $i++;
                            ?>
                                <tr class="listItem">
                                    <td class="a-center" style="height:30px;">
                                    <?php echo $i; ?>
                                </td>
                                <td style="padding:8px 5px;">
                                    <?php echo $rs['fullname']; ?>
                                </td>
                                <td style="padding:8px 5px;">
                                    <a href="/<?php echo $config ['admin_section']; ?>/question/<?php echo $config['page']; ?>?action=viewAnswer&id=<?php echo $rs['id']; ?>&keepThis=true&TB_iframe=true&height=400&width=500" title="<?php echo $rs['fullname']; ?>" class="thickbox">
                                        <?php echo cutString($rs['answer'], 80); ?>
                                    </a>
                                </td>
                                <td class="a-center">
                                    <?php
                                        echo $rs['active'] ? "Yes" : "No";
                                    ?>
                                    </td>
                                    <td align="center" style="font-size:10px;">
                                    <?php echo date("d/m/Y H:i:s", strtotime($rs['create_date'])); ?>
                                    </td>
                                    <td valign="middle" class="a-center">
                                        <input type="checkbox" id="multiId" name="multiId[]" value="<?php echo $rs['id']; ?>">
                                    </td>
                                </tr>

                            <?php
                                    }
                            ?>


                                </tbody>
                            </table>
                            <div style="text-align: right">
                                <select id="action" name="action" onchange="actionMultil(this.value);" style="width:120px; padding:0px;">
                                    <option value="">Select action</option>
                                    <option value="delete_answer">Delete</option>
                                    <option value="active_yes_answer">Set active yes</option>
                                    <option value="active_no_answer">Set active no</option>
                                </select>
                                <input type="hidden" value="delete" name="hDel" id="hDel" />
                                <b>Select all/Unselect all:</b>
                                <input type="checkbox" name="checkall" onclick="javascript: checkedAll('formView');">
                            </div>
                    <?php } ?>
                            </form>
                        </div>
                        <div class="linepagination">
                            <div class="pagination">
                                <ul>
                        <?php
                                echo pagingAdmin($answer['page'], $answer['totalPage']);
                        ?>
                            </ul>
                        </div>

                    </div>
                </div>

            </div>


        </div>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/footer.php'; ?>